package system;

import java.awt.*;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JLayeredPane;
import javax.swing.JInternalFrame;
import javax.swing.border.LineBorder;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import connect.connect;
import java.sql.*;
import java.util.Calendar;
import java.util.Vector;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.io.IOException;

import java.awt.Font;
import javax.swing.JFormattedTextField;
import javax.swing.JTable;
import javax.swing.event.CaretListener;
import javax.swing.event.CaretEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.text.*;
import system.Table;
import system.Login;
import system.Panel_1;

public class MainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField cu_name;
	private JTextField cu_phone;
	private JTextField address;
	private JTextField l_degree;
	private JTextField g_degree;
	private JTextField gd_shortname;
	private JTextField gd_name;
	private JTextField gd_pycode;
	private JTextField gd_property;
	private JTextField gd_specification;
	private JTextField gd_proplace;
	private JTextField gd_unit;
	private JTextField gd_type;
	private JTextField gd_serial;
	private JTextField gd_batch;
	private JTextField gd_price;
	private JTextField gd_supplier;
	private JTextField gd_pesticidereg;
	private JTextField gd_pesticidepro;
	private JTextField gd_safetylevel;
	private JTextField gd_barcode;
	private JTextField pi_id;
	private JTextField gd_name1;
	private JTextField gd_type1;
	private JTextField gd_unit1;
	private JTextField amount;
	private JTextField unitprice;
	private JTextField tax;
	private JTextField taxprice;
	private JTextField total;
	private JTable table;
	private JFormattedTextField pi_time;
	private JComboBox department;
	private JComboBox yewuyuan;
	private JComboBox supplier;
	private JComboBox warehouse;
	private JTextArea memo;
	private JFormattedTextField zhidanren;
	private JFormattedTextField zd_time;
	private JFormattedTextField shenheren;
	private JFormattedTextField sh_time;
	private JLabel label_62;

	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
//					MainFrame frame = new MainFrame();
//					frame.setVisible(true);
					Login login=new Login();
					login.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	@SuppressWarnings("rawtypes")
	public MainFrame() {

		final DecimalFormat format = new DecimalFormat("0.0000");

		final JLabel label_60 = new JLabel("欢迎");
		label_60.setHorizontalAlignment(SwingConstants.RIGHT);
		label_60.setForeground(new Color(0, 128, 128));
		label_60.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		label_60.setBounds(640, 0, 200, 21);

		addComponentListener(new ComponentAdapter() {
			@Override
			public void componentShown(ComponentEvent e) {
				label_60.setText("欢迎 [" + Constant.getName() + "]");
			}
		});
		int width = Toolkit.getDefaultToolkit().getScreenSize().width;
		int height = Toolkit.getDefaultToolkit().getScreenSize().height;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(0, 0, width, height);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		JInternalFrame internalFrame = new JInternalFrame("");
		internalFrame.setBorder(new LineBorder(new Color(0, 0, 0)));
		internalFrame.setVisible(true);

		JLayeredPane layeredPane = new JLayeredPane();

		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_contentPane
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(internalFrame,
								GroupLayout.PREFERRED_SIZE, 320,
								GroupLayout.PREFERRED_SIZE)
						.addGap(18)
						.addComponent(layeredPane, GroupLayout.DEFAULT_SIZE,
								990, Short.MAX_VALUE).addContainerGap()));
		gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_contentPane
						.createSequentialGroup()
						.addGroup(
								gl_contentPane
										.createParallelGroup(
												Alignment.TRAILING, false)
										.addComponent(internalFrame,
												Alignment.LEADING)
										.addComponent(layeredPane,
												Alignment.LEADING))
						.addContainerGap(24, Short.MAX_VALUE)));

		layeredPane.add(label_60);

		JLabel lblNewLabel_1 = new JLabel("\u9000\u51FA");
		lblNewLabel_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				dispose();
			}
		});
		lblNewLabel_1.setForeground(new Color(0, 0, 255));
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.LEFT);
		lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		lblNewLabel_1.setBounds(850, 0, 55, 21);
		layeredPane.add(lblNewLabel_1);

		final JTabbedPane tabbedPane4 = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane4.setBounds(0, 0, 970, 710);
		layeredPane.add(tabbedPane4);
		PutInStorage.addPutInStorage(tabbedPane4);//显示入库单++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		PutOutStorage.addPutOutStorage(tabbedPane4);//显示出库单

		JPanel panel_8 = new JPanel();
		tabbedPane4.addTab("\u79FB\u5E93\u5355", null, panel_8, null);

		JPanel panel_9 = new JPanel();
		tabbedPane4.addTab("\u7269\u54C1\u8F6C\u6362\u5355", null, panel_9,
				null);

		JPanel panel_7 = new JPanel();
		tabbedPane4.addTab("\u635F\u574F\u5904\u7406\u5355", null, panel_7,
				null);
		tabbedPane4.setVisible(false);

		final JTabbedPane tabbedPane1 = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane1.setBounds(0, 0, 970, 710);
		layeredPane.add(tabbedPane1);
		// tabbedPane1.setVisible(false);

		final JComboBox province = new JComboBox();
		province.setBounds(359, 214, 66, 23);
		final JComboBox city = new JComboBox();
		city.setBounds(431, 214, 66, 23);
		final JComboBox district = new JComboBox();
		district.setBounds(507, 214, 66, 23);
		final JComboBox cu_id = new JComboBox();
		cu_id.setBounds(359, 93, 126, 23);
		final JTextArea cu_location = new JTextArea();
		cu_location.setBounds(359, 253, 344, 50);
		final JTextArea cu_memo = new JTextArea();
		cu_memo.setBounds(359, 389, 344, 50);

		cu_id.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent arg0) {
				try {

					String sql = "SELECT * FROM Customer where cu_id= '"
							+ cu_id.getSelectedItem() + "'";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					ResultSet rs = stat.executeQuery(sql);

					while (rs.next()) { // 依次取出数据

						cu_name.setText(rs.getString(2));
						cu_phone.setText(rs.getString(3));
						String[] arr = rs.getString(4).split(",");
						province.setSelectedItem(arr[0]);
						city.setSelectedItem(arr[1]);
						district.setSelectedItem(arr[2]);
						address.setText(arr[3]);
						cu_location.setText(rs.getString(5));
						l_degree.setText(format.format(rs.getFloat(6))
								.toString());
						g_degree.setText(format.format(rs.getFloat(7))
								.toString());
						cu_memo.setText(rs.getString(8));
					}
					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e1) {
					e1.printStackTrace();
				}

			}
		});

		city.addItemListener(new ItemListener() {
			@SuppressWarnings("unchecked")
			public void itemStateChanged(ItemEvent e) {
				district.removeAllItems();
				try {
					String r = "";
					String sql = "SELECT District.di_name FROM District,City where District.ci_id =City.ci_id and City.ci_name= '"
							+ city.getSelectedItem() + "'";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					ResultSet rs = stat.executeQuery(sql);

					while (rs.next()) { // 依次取出数据
						r = rs.getString("di_name");
						district.addItem(r);
					}
					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
		});

		province.addItemListener(new ItemListener() {
			@SuppressWarnings("unchecked")
			public void itemStateChanged(ItemEvent arg0) {
				city.removeAllItems();
				district.removeAllItems();
				try {
					String r = "";
					String sql = "SELECT City.ci_name FROM City,Province where City.pr_id =Province.pr_id and Province.pr_name= '"
							+ province.getSelectedItem() + "'";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					ResultSet rs = stat.executeQuery(sql);

					while (rs.next()) { // 依次取出数据
						r = rs.getString("ci_name");
						city.addItem(r);
					}
					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		});

		JPanel panel = new JPanel();
		panel.addComponentListener(new ComponentAdapter() {
			@SuppressWarnings("unchecked")
			@Override
			public void componentShown(ComponentEvent arg0) {
				province.removeAllItems();
				city.removeAllItems();
				district.removeAllItems();
				cu_id.removeAllItems();
				cu_name.setText("");
				cu_phone.setText("");

				address.setText("");
				cu_location.setText("");
				l_degree.setText("");
				g_degree.setText("");
				cu_memo.setText("");
				try {
					String r = "";
					String sql = "SELECT * FROM Province";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					ResultSet rs = stat.executeQuery(sql);
					while (rs.next()) { // 依次取出数据
						r = rs.getString("pr_name");
						province.addItem(r);
					}
					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}

				cu_id.removeAllItems();
				try {
					int r = 0;
					String sql = "SELECT MAX(cu_id) FROM Customer";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					ResultSet rs = stat.executeQuery(sql);

					while (rs.next()) { // 依次取出数据
						r = rs.getInt(1) + 1;
						cu_id.addItem(r);
						cu_id.setEnabled(false);
					}

					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}

			}
		});
		tabbedPane1.addTab("\u5BA2\u6237\u4FE1\u606F", null, panel, null);
		tabbedPane1.setEnabledAt(0, true);

		JLabel label_2 = new JLabel("客户信息登记");
		label_2.setBounds(357, 33, 250, 24);
		label_2.setHorizontalAlignment(SwingConstants.CENTER);
		label_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));

		JLabel label_3 = new JLabel("客户编号");
		label_3.setBounds(284, 87, 65, 34);
		label_3.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		
		JLabel label_4 = new JLabel("客户名称");
		label_4.setBounds(284, 127, 65, 34);
		label_4.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		
		JLabel label_5 = new JLabel("客户电话");
		label_5.setBounds(284, 167, 65, 34);
		label_5.setFont(new Font("微软雅黑", Font.PLAIN, 15));

		JLabel label_6 = new JLabel("客户地址");
		label_6.setBounds(284, 207, 65, 34);
		label_6.setFont(new Font("微软雅黑", Font.PLAIN, 15));

		JLabel label_7 = new JLabel("经度");
		label_7.setHorizontalAlignment(SwingConstants.RIGHT);
		label_7.setBounds(284, 318, 59, 22);
		label_7.setFont(new Font("微软雅黑", Font.PLAIN, 15));

		JLabel label_8 = new JLabel("纬度");
		label_8.setHorizontalAlignment(SwingConstants.RIGHT);
		label_8.setBounds(284, 350, 59, 21);
		label_8.setFont(new Font("微软雅黑", Font.PLAIN, 15));

		JLabel label_9 = new JLabel("位置说明");
		label_9.setBounds(284, 247, 65, 34);
		label_9.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		
		JLabel label_10 = new JLabel("备注:");
		label_10.setHorizontalAlignment(SwingConstants.RIGHT);
		label_10.setBounds(284, 405, 59, 26);
		label_10.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		
		final JButton add = new JButton("添加");
		add.setBounds(305, 484, 60, 25);
		add.setFont(new Font("微软雅黑", Font.PLAIN, 10));
		add.setEnabled(false);
		final JButton update = new JButton("修改");
		update.setFont(new Font("微软雅黑", Font.PLAIN, 10));
		update.setBounds(506, 484, 60, 25);
		update.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				add.setEnabled(true);
				if (cu_name.getText().trim().length() == 0
						|| cu_phone.getText().trim().length() == 0
						|| address.getText().trim().length() == 0
						|| l_degree.getText().trim().length() == 0
						|| g_degree.getText().trim().length() == 0
				// || cu_location.getText().trim().length() == 0
				// || cu_memo.getText().trim().length() == 0
				) {
					JOptionPane.showMessageDialog(null, "请完善信息！");
					// cu_name.requestFocus(true);
					return;
				}

				try {

					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();

					String sql = "SELECT * FROM Customer where cu_id= '"
							+ cu_id.getSelectedItem() + "'";
					String sql_1 = "insert into Customer(cu_id,cu_name,cu_phone,cu_address,cu_longitude,cu_latitude,cu_location,cu_memo) values('"
							+ cu_id.getSelectedItem()
							+ "','"
							+ cu_name.getText()
							+ "','"
							+ cu_phone.getText()
							+ "','"
							+ province.getSelectedItem()
							+ ","
							+ city.getSelectedItem()
							+ ","
							+ district.getSelectedItem()
							+ ","
							+ address.getText()
							+ "','"
							+ l_degree.getText()
							+ "','"
							+ g_degree.getText()
							+ "','"
							+ cu_location.getText()
							+ "','"
							+ cu_memo.getText()
							+ "') ";

					String sql_2 = "update Customer set cu_name='"
							+ cu_name.getText() + "',cu_phone='"
							+ cu_phone.getText() + "',cu_address='"
							+ province.getSelectedItem() + ","
							+ city.getSelectedItem() + ","
							+ district.getSelectedItem() + ","
							+ address.getText() + "',cu_longitude='"
							+ l_degree.getText() + "',cu_latitude='"
							+ g_degree.getText() + "',cu_location='"
							+ cu_location.getText() + "',cu_memo='"
							+ cu_memo.getText() + "' where cu_id='"
							+ cu_id.getSelectedItem() + "' ";

					ResultSet rs = stat.executeQuery(sql);

					if (rs.next()) {

						int rs_2 = stat.executeUpdate(sql_2);
						if (rs_2 > 0) {
							JOptionPane.showMessageDialog(null, " 更新成功！");
						}

					} else {

						int rs_1 = stat.executeUpdate(sql_1);
						if (rs_1 > 0) {
							JOptionPane.showMessageDialog(null, " 添加成功！");

						}
					}

					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e1) {
					e1.printStackTrace();
				}

			}
		});

		final JButton delete = new JButton("删除");
		delete.setBounds(607, 484, 60, 25);
		delete.setFont(new Font("微软雅黑", Font.PLAIN, 10));
		delete.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				try {

					String sql = "delete  FROM Customer where cu_id='"
							+ cu_id.getSelectedItem() + "'";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					int rs = stat.executeUpdate(sql);

					if (rs > 0) { // 依次取出数据
						JOptionPane.showMessageDialog(null, " 删除成功！");
						cu_id.removeItem(cu_id.getSelectedItem());
					}

					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}

			}
		});
		delete.setEnabled(false);

		add.addMouseListener(new MouseAdapter() {
			@SuppressWarnings("unchecked")
			@Override
			public void mouseClicked(MouseEvent arg0) {
				delete.setEnabled(false);
				cu_id.removeAllItems();
				cu_name.setText("");
				cu_phone.setText("");

				address.setText("");
				cu_location.setText("");
				l_degree.setText("");
				g_degree.setText("");
				cu_memo.setText("");

				try {
					int r = 0;
					String sql = "SELECT MAX(cu_id) FROM Customer";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					ResultSet rs = stat.executeQuery(sql);

					while (rs.next()) { // 依次取出数据
						r = rs.getInt(1) + 1;
						cu_id.addItem(r);
						cu_id.setEnabled(false);
					}

					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}

			}
		});

		JButton edit = new JButton("\u4FEE\u6539");
		edit.setBounds(405, 484, 60, 25);

		edit.addMouseListener(new MouseAdapter() {
			@SuppressWarnings("unchecked")
			@Override
			public void mouseClicked(MouseEvent e) {
				cu_id.removeAllItems();
				cu_id.setEnabled(true);
				delete.setEnabled(true);
				try {
					int r = 0;
					String sql = "SELECT cu_id FROM Customer";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					ResultSet rs = stat.executeQuery(sql);

					while (rs.next()) { // 依次取出数据
						r = rs.getInt(1);
						cu_id.addItem(r);

					}

					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e1) {
					e1.printStackTrace();
				}

			}
		});

		cu_name = new JTextField();
		cu_name.setBounds(359, 134, 126, 21);
		cu_name.setColumns(10);

		cu_phone = new JTextField();
		cu_phone.setBounds(359, 174, 126, 21);
		cu_phone.setColumns(10);

		address = new JTextField();
		address.setBounds(579, 214, 124, 21);
		address.setColumns(10);

		l_degree = new JTextField();
		l_degree.setBounds(359, 319, 126, 21);
		l_degree.setColumns(10);

		JLabel label_11 = new JLabel("\u5EA6");
		label_11.setBounds(503, 322, 24, 15);

		g_degree = new JTextField();
		g_degree.setBounds(359, 350, 126, 21);
		g_degree.setColumns(10);

		JLabel label_14 = new JLabel("\u5EA6");
		label_14.setBounds(503, 353, 24, 15);
		panel.setLayout(null);
		panel.add(label_2);
		panel.add(label_9);
		panel.add(cu_location);
		panel.add(add);
		panel.add(edit);
		panel.add(update);
		panel.add(delete);
		panel.add(label_7);
		panel.add(label_8);
		panel.add(label_10);
		panel.add(cu_memo);
		panel.add(l_degree);
		panel.add(label_11);
		panel.add(g_degree);
		panel.add(label_14);
		panel.add(label_3);
		panel.add(label_4);
		panel.add(label_5);
		panel.add(cu_phone);
		panel.add(cu_name);
		panel.add(cu_id);
		panel.add(address);
		panel.add(label_6);
		panel.add(province);
		panel.add(city);
		panel.add(district);
		JLabel label_1 = new JLabel("\u5546\u54C1\u4FE1\u606F\u5F55\u5165");
		label_1.setBounds(357, 10, 250, 24);
		label_1.setHorizontalAlignment(SwingConstants.CENTER);
		label_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		final JComboBox gd_id = new JComboBox();
		final JButton add_1 = new JButton("\u65B0\u589E");
		final JButton delete_1 = new JButton("\u5220\u9664");
		delete_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {

				try {

					String sql = "delete  FROM Good where gd_id='"
							+ gd_id.getSelectedItem() + "'";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					int rs = stat.executeUpdate(sql);

					if (rs > 0) { // 依次取出数据
						JOptionPane.showMessageDialog(null, " 删除成功！");
						gd_id.removeItem(gd_id.getSelectedItem());
					}

					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e1) {
					e1.printStackTrace();
				}

			}
		});
		delete_1.setBounds(604, 470, 60, 25);
		delete_1.setEnabled(false);
		gd_shortname = new JTextField();
		gd_shortname.setBounds(326, 92, 110, 21);
		gd_shortname.setColumns(10);

		gd_name = new JTextField();
		gd_name.setBounds(567, 63, 110, 21);
		gd_name.setColumns(10);

		gd_pycode = new JTextField();
		gd_pycode.setBounds(567, 90, 110, 21);
		gd_pycode.setColumns(10);

		JLabel label_22 = new JLabel("\u62FC\u97F3\u7801\uFF1A");
		label_22.setBounds(491, 90, 72, 15);

		JLabel label_12 = new JLabel("\u7269\u54C1\u5C5E\u6027\uFF1A");
		label_12.setBounds(257, 119, 65, 15);

		gd_property = new JTextField();
		gd_property.setBounds(326, 119, 110, 21);
		gd_property.setColumns(10);

		JLabel label_13 = new JLabel("\u7269\u54C1\u89C4\u683C\uFF1A");
		label_13.setBounds(491, 117, 72, 15);

		gd_specification = new JTextField();
		gd_specification.setBounds(567, 117, 110, 21);
		gd_specification.setColumns(10);

		JLabel label_15 = new JLabel("\u5305\u88C5\u7C7B\u578B\uFF1A");
		label_15.setBounds(257, 146, 65, 15);

		gd_proplace = new JTextField();
		gd_proplace.setBounds(567, 144, 110, 21);
		gd_proplace.setColumns(10);

		JLabel label_16 = new JLabel("\u7269\u54C1\u4EA7\u5730\uFF1A");
		label_16.setBounds(491, 144, 72, 15);

		JLabel label_17 = new JLabel("\u8BA1\u91CF\u5355\u4F4D\uFF1A");
		label_17.setBounds(257, 173, 65, 15);

		gd_unit = new JTextField();
		gd_unit.setBounds(326, 173, 110, 21);
		gd_unit.setColumns(10);

		gd_type = new JTextField();
		gd_type.setBounds(326, 146, 110, 21);
		gd_type.setColumns(10);

		gd_serial = new JTextField();
		gd_serial.setBounds(567, 171, 110, 21);
		gd_serial.setColumns(10);

		JLabel label_18 = new JLabel("\u5E8F\u5217\u53F7\uFF1A");
		label_18.setBounds(491, 171, 72, 15);

		gd_batch = new JTextField();
		gd_batch.setBounds(567, 205, 110, 21);
		gd_batch.setColumns(10);

		JLabel label_23 = new JLabel("\u6279\u6B21\uFF1A");
		label_23.setBounds(498, 205, 65, 15);

		JLabel label_24 = new JLabel("\u8FC7\u671F\u65E5\u671F\uFF1A");
		label_24.setHorizontalAlignment(SwingConstants.RIGHT);
		label_24.setBounds(244, 236, 72, 15);

		JLabel label_25 = new JLabel("\u7269\u54C1\u4EF7\u683C\uFF1A");
		label_25.setBounds(498, 236, 65, 15);

		gd_price = new JTextField();
		gd_price.setBounds(567, 236, 110, 21);
		gd_price.setColumns(10);

		gd_supplier = new JTextField();
		gd_supplier.setBounds(326, 267, 110, 21);
		gd_supplier.setColumns(10);

		JLabel label_26 = new JLabel("\u4F9B\u8D27\u5355\u4F4D\uFF1A");
		label_26.setHorizontalAlignment(SwingConstants.RIGHT);
		label_26.setBounds(225, 267, 91, 15);

		gd_pesticidereg = new JTextField();
		gd_pesticidereg.setBounds(567, 267, 110, 21);
		gd_pesticidereg.setColumns(10);

		JLabel label_27 = new JLabel("\u519C\u836F\u7F16\u53F7\uFF1A");
		label_27.setBounds(498, 267, 65, 15);

		JLabel label_28 = new JLabel("\u751F\u4EA7\u6279\u51C6\u53F7\uFF1A");
		label_28.setHorizontalAlignment(SwingConstants.RIGHT);
		label_28.setBounds(225, 298, 91, 15);

		gd_pesticidepro = new JTextField();
		gd_pesticidepro.setBounds(326, 298, 110, 21);
		gd_pesticidepro.setColumns(10);

		gd_safetylevel = new JTextField();
		gd_safetylevel.setBounds(567, 295, 110, 21);
		gd_safetylevel.setColumns(10);

		final JFormattedTextField gd_overtime = new JFormattedTextField();
		gd_overtime.setHorizontalAlignment(SwingConstants.LEFT);

		JLabel label_29 = new JLabel("\u5B89\u5168\u7EA7\u522B\uFF1A");
		label_29.setBounds(491, 298, 65, 15);

		JLabel label_30 = new JLabel("\u5907\u6CE8\uFF1A");
		label_30.setBounds(279, 340, 43, 15);

		final JTextArea gd_memo = new JTextArea();
		gd_memo.setBounds(326, 337, 351, 73);

		gd_id.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent arg0) {
				try {

					String sql = "SELECT * FROM Good where gd_id= '"
							+ gd_id.getSelectedItem() + "'";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					ResultSet rs = stat.executeQuery(sql);

					while (rs.next()) { // 依次取出数据
						gd_name.setText(rs.getString(2));
						gd_shortname.setText(rs.getString(3));
						gd_pycode.setText(rs.getString(4));
						gd_property.setText(rs.getString(5));
						gd_specification.setText(rs.getString(6));
						gd_type.setText(rs.getString(7));
						gd_proplace.setText(rs.getString(8));
						gd_unit.setText(rs.getString(9));
						gd_serial.setText(rs.getString(10));
						gd_barcode.setText(rs.getString(11));
						gd_batch.setText(rs.getString(12));
						gd_overtime.setText(rs.getDate(13).toString());
						gd_price.setText(rs.getString(14));
						gd_supplier.setText(rs.getString(15));
						gd_pesticidereg.setText(rs.getString(16));
						gd_pesticidepro.setText(rs.getString(17));
						gd_safetylevel.setText(rs.getString(18));
						gd_memo.setText(rs.getString(19));

					}
					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e1) {
					e1.printStackTrace();
				}

			}
		});
		gd_id.setBounds(326, 63, 110, 23);
		gd_id.setToolTipText("");

		add_1.addMouseListener(new MouseAdapter() {
			@SuppressWarnings("unchecked")
			@Override
			public void mouseClicked(MouseEvent e) {
				delete_1.setEnabled(false);
				gd_id.removeAllItems();
				gd_name.setText("");
				gd_shortname.setText("");
				gd_pycode.setText("");
				gd_property.setText("");
				gd_specification.setText("");
				gd_type.setText("");
				gd_proplace.setText("");
				gd_unit.setText("");
				gd_serial.setText("");
				gd_barcode.setText("");
				gd_batch.setText("");
				gd_overtime.setText("");
				gd_price.setText("");
				gd_supplier.setText("");
				gd_pesticidereg.setText("");
				gd_pesticidepro.setText("");
				gd_safetylevel.setText("");
				gd_memo.setText("");

				try {
					int r = 0;
					String sql = "SELECT MAX(gd_id) FROM Good";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					ResultSet rs = stat.executeQuery(sql);

					while (rs.next()) { // 依次取出数据
						r = rs.getInt(1) + 1;
						gd_id.addItem(r);
						gd_id.setEnabled(false);
					}

					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e1) {
					e1.printStackTrace();
				}

			}
		});
		add_1.setBounds(302, 470, 60, 25);
		add_1.setEnabled(false);

		JButton edit_1 = new JButton("\u4FEE\u6539");
		edit_1.addMouseListener(new MouseAdapter() {
			@SuppressWarnings("unchecked")
			@Override
			public void mouseClicked(MouseEvent e) {
				gd_id.removeAllItems();
				gd_id.setEnabled(true);
				delete_1.setEnabled(true);
				try {
					int r = 0;
					String sql = "SELECT gd_id FROM Good";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					ResultSet rs = stat.executeQuery(sql);

					while (rs.next()) { // 依次取出数据
						r = rs.getInt(1);
						gd_id.addItem(r);

					}

					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e1) {
					e1.printStackTrace();
				}

			}
		});
		edit_1.setBounds(402, 470, 60, 25);

		JLabel label_19 = new JLabel("\u7269\u54C1\u7F16\u53F7\uFF1A");
		label_19.setBounds(257, 63, 65, 15);

		JLabel label_20 = new JLabel("\u7269\u54C1\u540D\u79F0\uFF1A");
		label_20.setBounds(491, 63, 72, 15);

		JLabel label_21 = new JLabel("\u7269\u54C1\u7B80\u79F0\uFF1A");
		label_21.setBounds(257, 92, 65, 15);

		JButton submit_1 = new JButton("\u4FDD\u5B58");
		submit_1.setBounds(503, 470, 60, 25);
		submit_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				add_1.setEnabled(true);
				if (gd_name.getText().trim().length() == 0
						|| gd_shortname.getText().trim().length() == 0
						|| gd_pycode.getText().trim().length() == 0
						|| gd_unit.getText().trim().length() == 0
						|| gd_barcode.getText().trim().length() == 0
				// || cu_location.getText().trim().length() == 0
				// || cu_memo.getText().trim().length() == 0
				) {
					JOptionPane.showMessageDialog(null, "请完善信息！");
					// cu_name.requestFocus(true);
					return;
				}

				try {

					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();

					String sql = "SELECT * FROM Good where gd_id= '"
							+ gd_id.getSelectedItem() + "'";
					String sql_1 = "insert into good(gd_id,gd_name,gd_shortname,gd_pycode,gd_property,gd_specification,gd_type,gd_proplace,gd_unit,gd_serial,gd_barcode,gd_batch,gd_overtime,gd_price,gd_supplier,gd_pesticidereg,gd_pesticidepro,gd_safetylevel,gd_memo) values('"
							+ gd_id.getSelectedItem()
							+ "','"
							+ gd_name.getText()
							+ "','"
							+ gd_shortname.getText()
							+ "','"
							+ gd_pycode.getText()
							+ "','"
							+ gd_property.getText()
							+ "','"
							+ gd_specification.getText()
							+ "','"
							+ gd_type.getText()
							+ "','"
							+ gd_proplace.getText()
							+ "','"
							+ gd_unit.getText()
							+ "','"
							+ gd_serial.getText()
							+ "','"
							+ gd_barcode.getText()
							+ "','"
							+ gd_batch.getText()
							+ "','"
							+ gd_overtime.getText()
							+ "','"
							+ gd_price.getText()
							+ "','"
							+ gd_supplier.getText()
							+ "','"
							+ gd_pesticidereg.getText()
							+ "','"
							+ gd_pesticidepro.getText()
							+ "','"
							+ gd_safetylevel.getText()
							+ "','"
							+ gd_memo.getText() + "') ";

					String sql_2 = "update Good set gd_name='"
							+ gd_name.getText() + "',gd_shortname='"
							+ gd_shortname.getText() + "',gd_pycode='"
							+ gd_pycode.getText() + "',gd_property='"
							+ gd_property.getText() + "',gd_specification='"
							+ gd_specification.getText() + "',gd_type='"
							+ gd_type.getText() + "',gd_proplace='"
							+ gd_proplace.getText() + "',gd_unit='"
							+ gd_unit.getText() + "',gd_serial='"
							+ gd_serial.getText() + "',gd_barcode='"
							+ gd_barcode.getText() + "',gd_batch='"
							+ gd_batch.getText() + "',gd_overtime='"
							+ gd_overtime.getText() + "',gd_price='"
							+ gd_price.getText() + "',gd_supplier='"
							+ gd_supplier.getText() + "',gd_pesticidereg='"
							+ gd_pesticidereg.getText() + "',gd_pesticidepro='"
							+ gd_pesticidepro.getText() + "',gd_safetylevel='"
							+ gd_safetylevel.getText() + "'where gd_id='"
							+ gd_id.getSelectedItem() + "' ";

					ResultSet rs = stat.executeQuery(sql);

					if (rs.next()) {

						int rs_2 = stat.executeUpdate(sql_2);
						if (rs_2 > 0) {
							JOptionPane.showMessageDialog(null, " 更新成功！");
						}

					} else {

						int rs_1 = stat.executeUpdate(sql_1);
						if (rs_1 > 0) {
							JOptionPane.showMessageDialog(null, " 添加成功！");

						}
					}

					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e1) {
					e1.printStackTrace();
				}

			}
		});

		JPanel panel_5 = new JPanel();
		panel_5.addComponentListener(new ComponentAdapter() {
			@SuppressWarnings("unchecked")
			@Override
			public void componentShown(ComponentEvent arg0) {
				gd_id.removeAllItems();
				gd_id.removeAllItems();
				gd_name.setText("");
				gd_shortname.setText("");
				gd_pycode.setText("");
				gd_property.setText("");
				gd_specification.setText("");
				gd_type.setText("");
				gd_proplace.setText("");
				gd_unit.setText("");
				gd_serial.setText("");
				gd_barcode.setText("");
				gd_batch.setText("");
				gd_overtime.setText("");
				gd_price.setText("");
				gd_supplier.setText("");
				gd_pesticidereg.setText("");
				gd_pesticidepro.setText("");
				gd_safetylevel.setText("");
				gd_memo.setText("");

				try {
					int r = 0;
					String sql = "SELECT MAX(gd_id) FROM Good";
					Connection conn = connect.getConnection();
					Statement stat = conn.createStatement();
					ResultSet rs = stat.executeQuery(sql);

					while (rs.next()) { // 依次取出数据
						r = rs.getInt(1) + 1;
						gd_id.addItem(r);
						gd_id.setEnabled(false);
					}

					stat.close();
					conn.close();
				} catch (SQLException sqlex) {
					sqlex.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}

			}
		});
		tabbedPane1.addTab("\u5546\u54C1\u4FE1\u606F", null, panel_5, null);
		panel_5.setLayout(null);
		panel_5.add(label_1);
		panel_5.add(label_19);
		panel_5.add(label_15);
		panel_5.add(label_12);
		panel_5.add(label_21);
		panel_5.add(label_23);
		panel_5.add(label_17);
		panel_5.add(label_25);
		panel_5.add(label_27);
		panel_5.add(label_29);
		panel_5.add(label_30);
		panel_5.add(gd_pesticidereg);
		panel_5.add(gd_batch);
		panel_5.add(gd_unit);
		panel_5.add(gd_id);
		panel_5.add(gd_shortname);
		panel_5.add(gd_property);
		panel_5.add(gd_type);
		panel_5.add(gd_price);
		panel_5.add(gd_safetylevel);
		panel_5.add(label_28);
		panel_5.add(label_26);
		panel_5.add(label_24);
		panel_5.add(label_18);
		panel_5.add(label_16);
		panel_5.add(label_13);
		panel_5.add(label_22);
		panel_5.add(label_20);
		panel_5.add(gd_supplier);
		panel_5.add(gd_name);
		panel_5.add(gd_pycode);
		panel_5.add(gd_specification);
		panel_5.add(gd_proplace);
		panel_5.add(gd_serial);
		panel_5.add(gd_pesticidepro);
		panel_5.add(gd_memo);
		panel_5.add(add_1);
		panel_5.add(edit_1);
		panel_5.add(submit_1);
		panel_5.add(delete_1);

		gd_barcode = new JTextField();
		gd_barcode.setColumns(10);
		gd_barcode.setBounds(326, 205, 110, 21);
		panel_5.add(gd_barcode);

		JLabel label_31 = new JLabel("\u6761\u5F62\u7801\uFF1A");
		label_31.setHorizontalAlignment(SwingConstants.RIGHT);
		label_31.setBounds(225, 205, 90, 15);
		panel_5.add(label_31);

		gd_overtime.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {

				DateChooser mDateChooser = new DateChooser(gd_overtime);
				// 设置DateChooser弹出位置
				Point p = gd_overtime.getLocationOnScreen();
				p.y = p.y + 30;
				mDateChooser.showDateChooser(p);
				gd_overtime.requestFocusInWindow();
			}
		});
		gd_overtime.setBounds(326, 233, 110, 21);
		panel_5.add(gd_overtime);

		JPanel panel_2 = new JPanel();
		tabbedPane1.addTab("\u5408\u540C\u7BA1\u7406", null, panel_2, null);

		JLabel label = new JLabel("1");
		panel_2.add(label);

		final JTabbedPane tabbedPane2 = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane2.setBounds(0, 0, 970, 710);
		layeredPane.add(tabbedPane2);
		tabbedPane2.setVisible(false);

		JPanel panel_3 = new JPanel();
		tabbedPane2.addTab("1", null, panel_3, null);

		JLabel lblNewLabel = new JLabel("New label");
		panel_3.add(lblNewLabel);

		JPanel panel_4 = new JPanel();
		tabbedPane2.addTab("2", null, panel_4, null);

		final JTabbedPane tabbedPane3 = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane3.setBounds(0, 0, 970, 710);
		layeredPane.add(tabbedPane3);
		tabbedPane3.setVisible(false);

		JButton button1 = new JButton("\u4FE1\u606F\u7BA1\u7406");
		button1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				tabbedPane1.setVisible(true);
				tabbedPane2.setVisible(false);
				tabbedPane3.setVisible(false);
				tabbedPane4.setVisible(false);
			}
		});

		JButton button2 = new JButton("\u8BA1\u5212\u7BA1\u7406");
		button2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				tabbedPane1.setVisible(false);
				tabbedPane2.setVisible(true);
				tabbedPane3.setVisible(false);
				tabbedPane4.setVisible(false);
			}
		});

		JButton button3 = new JButton("\u5DE5\u4F5C\u7BA1\u7406");
		button3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				tabbedPane1.setVisible(false);
				tabbedPane2.setVisible(false);
				tabbedPane3.setVisible(true);
				tabbedPane4.setVisible(false);
			}
		});

		JButton button4 = new JButton("\u4ED3\u50A8\u7BA1\u7406");
		button4.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				tabbedPane1.setVisible(false);
				tabbedPane2.setVisible(false);
				tabbedPane3.setVisible(false);
				tabbedPane4.setVisible(true);
			}
		});
		GroupLayout groupLayout = new GroupLayout(
				internalFrame.getContentPane());
		groupLayout
				.setHorizontalGroup(groupLayout
						.createParallelGroup(Alignment.LEADING)
						.addGroup(
								groupLayout
										.createSequentialGroup()
										.addGap(72)
										.addGroup(
												groupLayout
														.createParallelGroup(
																Alignment.LEADING)
														.addComponent(
																button4,
																GroupLayout.PREFERRED_SIZE,
																174,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																button3,
																GroupLayout.PREFERRED_SIZE,
																174,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																button2,
																GroupLayout.PREFERRED_SIZE,
																174,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																button1,
																GroupLayout.PREFERRED_SIZE,
																174,
																GroupLayout.PREFERRED_SIZE))
										.addGap(72)));
		groupLayout.setVerticalGroup(groupLayout.createParallelGroup(
				Alignment.LEADING).addGroup(
				groupLayout
						.createSequentialGroup()
						.addGap(102)
						.addComponent(button1, GroupLayout.PREFERRED_SIZE, 43,
								GroupLayout.PREFERRED_SIZE)
						.addGap(18)
						.addComponent(button2, GroupLayout.PREFERRED_SIZE, 43,
								GroupLayout.PREFERRED_SIZE)
						.addGap(18)
						.addComponent(button3, GroupLayout.PREFERRED_SIZE, 43,
								GroupLayout.PREFERRED_SIZE)
						.addGap(18)
						.addComponent(button4, GroupLayout.PREFERRED_SIZE, 43,
								GroupLayout.PREFERRED_SIZE)
						.addContainerGap(360, Short.MAX_VALUE)));
		internalFrame.getContentPane().setLayout(groupLayout);
		contentPane.setLayout(gl_contentPane);
		
		
	
	}

	
	
	
	
	public static boolean isNotNumber(String str) {
		boolean a = true;
		if (str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$")) {
			a = false;
		}
		return a;
	}
	
	public static String getCurrentDate(){
		 int year=0;
	        int month=0;
	        int day=0;
	        Calendar c=Calendar.getInstance();//获得系统当前日期
	        year=c.get(Calendar.YEAR);
	        month=c.get(Calendar.MONTH)+1;//系统日期从0开始算起
	        day=c.get(Calendar.DAY_OF_MONTH);
	        String date=String.valueOf(year)+"/"+String.valueOf(month)+"/"+String.valueOf(day);
	        return date;
	}
	
	
}
